package com.graduation.community_manager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.graduation.community_manager.entity.CmHouseEntity;
import com.graduation.community_manager.service.CmHouseService;
import com.graduation.community_manager.vo.PageCmHouseVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户住房表
 *
 * @author wdh
 */
@RestController
@CrossOrigin
@RequestMapping("/cmHouse")
public class CmHouseController {

    @Autowired
    private CmHouseService cmHouseService;

    /**
     * 保存用户住房
     */
    @ApiOperation(value = "保存用户住房")
    @PostMapping("/save")
    public Boolean save(@RequestBody CmHouseEntity cmHouseEntity){
        cmHouseService.save(cmHouseEntity);
        return true;
    }

    /**
     * 更新用户住房
     */
    @ApiOperation(value = "更新用户住房信息")
    @PutMapping("/update")
    public Boolean update(@RequestBody CmHouseEntity cmHouseEntity) {
        cmHouseService.updateById(cmHouseEntity);
        return true;
    }

    /**
     * 根据用户id查询用户住房
     */
    @ApiOperation(value = "获得用户住房信息")
    @GetMapping("/info")
    public List<CmHouseEntity> getCmHouseInfoList(@RequestBody PageCmHouseVO vo){
        List<CmHouseEntity> list = cmHouseService.getCmHouseInfoList(vo);
        return list;
    }

    /**
     * 获得用户住房信息分页
     */
    @ApiOperation(value = "获得用户住房分页")
    @GetMapping("/page")
    public IPage<CmHouseEntity> cmHousePage(@RequestBody PageCmHouseVO pageCmHouseVO){
        return cmHouseService.cmHousePage(pageCmHouseVO);
    }

    /**
     * 删除用户住房信息
     */
    @ApiOperation(value = "删除用户住房信息")
    @DeleteMapping("/delete")
    public Boolean delete(@RequestParam("id") Long id) {
        return cmHouseService.removeById(id);
    }
}
